﻿
@{
    ViewBag.Title = "菜单首页";
    Layout = "~/Views/Shared/_Layout_Content.cshtml";
}
@section styles
{
    <link href="/Content/css/plugins/jqgrid/ui.jqgrid.css" rel="stylesheet" />
    <link href="~/Content/css/plugins/datapicker/datepicker3.css" rel="stylesheet" />
}

<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>菜单管理</h5>
            <div class="ibox-tools">
                <a class="collapse-link">
                    <i class="fa fa-chevron-up"></i>
                </a>
            </div>
        </div>
        <div class="ibox-content">
            <div class="form-group">
                <button id="btnAdd" type="button" class="btn btn-primary " onclick="addModel()"><i class="fa fa-plus"></i>&nbsp;添加</button>
                <button id="btnEdit" type="button" class="btn btn-info " onclick="editModel()"><i class="fa fa-pencil"></i> 编辑</button>
                <button id="btnDel" type="button" class="btn btn-danger " onclick="delData()">
                    <i class="fa fa-remove"></i>&nbsp;&nbsp;<span class="bold">删除</span>
                </button>
            </div>

            <div class="form-group">
                <div class="input-group">
                    <input id="txtSearchKey" type="text" class="input form-control" placeholder="搜索关键字" />
                    <span class="input-group-btn">
                        <button id="btnSearch" class="btn btn btn-primary" type="button"> <i class="fa fa-search"></i> 搜索</button>
                    </span>
                </div>
            </div>

            <div class="jqGrid_wrapper">
                <table id="table_list"></table>
                <div id="pager_list"></div>
            </div>
        </div>
    </div>
</div>

@section scripts
{
    @Scripts.Render("~/content/js/list")
    <script src="~/Content/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script>
        function searchData() { //搜索
            var json = {
                keywords: $("#txtSearchKey").val()
            };
            XPage.Search(json);
        }

        function addModel() {
            $("#btnAdd").button("loading");
            window.location.href = "@Url.Action("Add")";
        }

        function editModel() { //编辑
            var row = JucheapGrid.GetData();
            if (row != null) {
                $("#btnEdit").button("loading");
                window.location.href = "@Url.Action("Edit")/" + row.Id;
            } else {
                parent.layer.alert("请选择要编辑的数据");
            }
        }

        function delData() { //删除
            XPage.DelData("@Url.Action("Delete")");
        }

        $(document).ready(function() {
            var config = {
                title: '菜单列表',
                shrinkToFit: true,//超出宽度自动滚动
                url: '@Url.Action("GetListWithPager")',
                mtype: 'post',
                colNames: ['主键', '菜单名称', '类型', 'URL地址', '排序', '创建日期'],
                colModel: [
                    { name: 'Id', index: 'Id', width: 60, key: true, hidden: true, search: false, dataType: "text" },
                    {
                        name: 'Name', index: 'Name', width: 260, search: true, dataType: "text",
                        formatter: function (cellValue, options, rowObject) {
                            return "<span class='" + rowObject.Icon + "'></span> " + cellValue;
                        }
                    },
                    {
                        name: 'Type',
                        index: 'Type',
                        width: 160,
                        dataType: "text",
                        formatter: function(cellValue, options, rowObject) {
                            return rowObject.TypeName;
                        }
                    },
                    { name: 'Url', index: 'Url', width: 360, search: true, dataType: "text" },
                    { name: 'Order', index: 'Order', width: 260, search: true, dataType: "text" },
                    {
                        name: 'CreateDateTime',
                        index: 'CreateDateTime',
                        width: 360,
                        search: true,
                        dataType: "date",
                        formatter: function (cellValue, options, rowObject) {
                            return cellValue.getDate();
                        }
                    }
                ]
            };
            JucheapGrid.Load(config);
            $("#btnSearch").bind("click", searchData);
        });
    </script>
}
